package com.itcanteen.reggie.advice;

import com.itcanteen.reggie.common.R;
import com.itcanteen.reggie.exception.CustomerException;
import com.itcanteen.reggie.exception.NameExistsException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author baimugudu
 * @email 2415621370@qq.com
 * @date 2022/10/24 11:12
 */
@RestControllerAdvice
public class GlobalExceptionHandler {


    @ExceptionHandler(value = NameExistsException.class)
    public R ExceptionHandler(NameExistsException e){
        e.printStackTrace();
        return R.error(e.getMessage()+"已经存在");
    }

    @ExceptionHandler(CustomerException.class)
    public R customerExceptionHandler(CustomerException e){
        e.printStackTrace(); //打印异常信息，否则控制台没有任何的内容
        return R.error(e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public R exceptionHandler(Exception e){
        e.printStackTrace(); //打印异常信息，否则控制台没有任何的内容
        return R.error("目前访问人数过多，请稍后！");
    }
}
